//
//  HomeGongGaoViewController.m
//  GoBigMarket
//
//  Created by 王天义 on 16/8/31.
//  Copyright © 2016年 legend. All rights reserved.
//

#import "HomeGongGaoViewController.h"
#import "HomeGongGaoModel.h"

@interface HomeGongGaoViewController ()
@property (nonatomic ,strong)NSMutableArray *datas;
@end

@implementation HomeGongGaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"公告";
    self.tabBarController.tabBar.hidden = YES;
    [self getTopArticleInfo];
    
}

#pragma mark --- 获取公告详情

- (void)getTopArticleInfo{
    
    NSDictionary *par = @{@"ArticleId":self.ArticleId};
    [CQNetWorkTools GETWithURL:GetArticle par:par success:^(id responseObject) {
        if ([[responseObject objectForKey:@"Err"] intValue]) {
            DLog(@"%@",[responseObject objectForKey:@"ErrMsg"]);
            [SVProgressHUD  showWithStatus:[responseObject objectForKey:@"ErrMsg"]];
            [self performSelector:@selector(dismiss) withObject:nil afterDelay:1];

        }else{
            NSDictionary *dict = [responseObject objectForKey:@"Article"];
            HomeGongGaoModel *model = [HomeGongGaoModel mj_objectWithKeyValues:dict];
            self.nameLabel.text = model.Title;
            self.dateLabel.text = model.AddDate;
            self.infoLabel.text = [self filterHTML:model.Content];
            self.infoLabel.editable = NO;
        }
    } filed:^(NSError *error) {
        DLog(@"失败===%@", error);
        [SVProgressHUD  showWithStatus:@"请检查网络"];
        [self performSelector:@selector(dismiss) withObject:nil afterDelay:1];
    }];
}

-(NSString *)filterHTML:(NSString *)html
{
    NSScanner * scanner = [NSScanner scannerWithString:html];
    NSString * text = nil;
    while([scanner isAtEnd]==NO)
    {
        //找到标签的起始位置
        [scanner scanUpToString:@"<" intoString:nil];
        //找到标签的结束位置
        [scanner scanUpToString:@">" intoString:&text];
        //替换字符
        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""];
    }
    //    NSString * regEx = @"<([^>]*)>";
    //    html = [html stringByReplacingOccurrencesOfString:regEx withString:@""];
    return html;
}
- (void)dismiss{
    [SVProgressHUD dismiss];
}

@end
